package cn.livingCloud.service.impl.operation;

import cn.livingCloud.context.BeanProvider;
import cn.livingCloud.dto.CaseAssignmentFormDto;
import cn.livingCloud.dto.JsonDto;
import cn.livingCloud.entity.core.CaseStatus;
import cn.livingCloud.entity.core.Employee;
import cn.livingCloud.repository.EmployeeMapper;

import java.util.ArrayList;
import java.util.List;

/**
 * 案件分派
 * Created by 唐旭 on 2016/6/7.
 */
public class CaseAssignment extends CaseOperator {
    private CaseAssignmentFormDto formDto;
    private Employee employee;

    public CaseAssignment(CaseAssignmentFormDto formDto) {
        super(formDto);
        String employeeUuid = formDto.getEmployeeUuid();
        EmployeeMapper employeeMapper = BeanProvider.getBean(EmployeeMapper.class);
        employee = employeeMapper.selectByPrimaryKey(employeeUuid);
    }

    @Override
    protected JsonDto operation() {
        this.aCase.setStatus(CaseStatus.ASSIGNMENT);
        //发送分派的模板消息
        msgService.sendAssignmentMsg(aCase);

        JsonDto jsonDto = new JsonDto();
        jsonDto.setState(true);
        return jsonDto;
    }

    @Override
    protected String getContent() {
        String template = "案件分派至 [%s-%s] 处置";
        return String.format(template, employee.getDept().getName(), employee.getName());
    }

    @Override
    protected List<Employee> getNewOwners() {
        List<Employee> employeeList = new ArrayList<>();
        employeeList.add(employee);
        return employeeList;
    }
}
